﻿using NCP.Recruiting.ApplicationServices.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NCP.Recruiting.ApplicationServices.ViewModels
{
    public class CandidateItemViewModel
    {
        public Guid Id { get; set; }
        public bool IsChecked { get; set; }

        /// <summary>
        /// 来源
        /// </summary>
        public int Source { get; set; }
        public string SourceName
        {
            get
            {
                return this.Source == 2 ? "自选" : "应聘";
            }
        }

        /// <summary>
        /// 应聘职位
        /// </summary>
        public Guid? JobPositionId { get; set; }
        public string JobTitle { get; set; }

        public Guid ResumeId { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        public string FullName { get; set; }

        /// <summary>
        /// 文字标签
        /// </summary>
        public Guid? TagId { get; set; }
        public string TagIdName { get; set; }

        public DateTime? BirthDate { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        public int? Ages
        {
            get
            {

                if (!BirthDate.HasValue)
                {
                    return null;
                }

                var temp = DateTime.Now - BirthDate.Value;
                return (int)Math.Floor(temp.Days / 365.0);
            }
        }

        /// <summary>
        /// 性别
        /// </summary>
        public int Gender { get; set; }

        /// <summary>
        /// 工作经验
        /// </summary>
        public int? YearsOfExperience { get; set; }
        public string YearsOfExperienceName { get; set; }

        /// <summary>
        /// 教育程度/学历
        /// </summary>
        public int? EducationLevel { get; set; }
        public string EducationLevelName { get; set; }

        /// <summary>
        /// 联系电话(先取手机号，再取座机号)
        /// </summary>
        public string Phone { get; set; }

        /// <summary>
        /// 标记
        /// </summary>
        public int Status { get; set; }
        public string StatusName
        {
            get
            {
                var candidateStatus = this.Status;
                switch (candidateStatus)
                {
                    case 0:
                        {
                            return "未读";
                        }
                    case 1:
                        {
                            return "已读";
                        }
                    case 2:
                        {
                            return "已回复";
                        }
                    case 3:
                        {
                            return "已邀请";
                        }
                    default:
                        {
                            return "未读";
                        }
                }
            }
        }

        public virtual InterviewModel InterviewModel { get; set; }

        public virtual ResumeReplyModel ResumeReplyModel { get; set; }


        /// <summary>
        /// 接收邮件人列表
        /// </summary>
        public string Jobseekers { get; set; }

        /// <summary>
        /// 邮件模版
        /// </summary>
        public Guid TemplateId { get; set; }

        /// <summary>
        /// 消息模版
        /// </summary>
        public Guid MessageTemplateId { get; set; }

        /// <summary>
        /// 邀请面试邮件人列表
        /// </summary>
        public string InterviewJobseekers { get; set; }

        /// <summary>
        /// 接收日期
        /// </summary>
        public DateTime? DateSaved { get; set; }
        public string DateSavedString
        {
            get
            {
                if (DateSaved == null)
                {
                    return string.Empty;
                }

                var timeSpan = DateTime.Now - DateSaved.Value;
                if (timeSpan.Days > 1)
                {
                    return timeSpan.Days.ToString() + "天前";
                }
                if (timeSpan.Days == 1)
                {
                    return "昨天";
                }
                if (timeSpan.Hours > 0 && timeSpan.Hours < 24)
                {
                    return timeSpan.Hours.ToString() + "小时前";
                }
                return timeSpan.Seconds.ToString() + "分钟前";
            }
        }

        /// <summary>
        /// 处理日期
        /// </summary>
        public DateTime? DateReviewed { get; set; }
        public string DateReviewedString
        {
            get
            {
                if (DateReviewed == null)
                {
                    return string.Empty;
                }

                var timeSpan = DateTime.Now - DateReviewed.Value;
                if (timeSpan.Days > 1)
                {
                    return timeSpan.Days.ToString() + "天前";
                }
                if (timeSpan.Days == 1)
                {
                    return "昨天";
                }
                if (timeSpan.Hours > 0 && timeSpan.Hours < 24)
                {
                    return timeSpan.Hours.ToString() + "小时前";
                }
                return timeSpan.Seconds.ToString() + "分钟前";
            }
        }

        /// <summary>
        /// 已回复
        /// </summary>
        public bool? IsReplied { get; set; }

        /// <summary>
        /// 已标记
        /// </summary>
        public bool? IsMarked { get; set; }

        /// <summary>
        /// 简历ID
        /// </summary>
        public string ReferenceNumber { get; set; }

        /// <summary>
        /// 求职信内容
        /// </summary>
        public string CoverLetter { get; set; }

        /// <summary>
        /// 已读
        /// </summary>
        public bool IsReadLetter
        {
            get
            {
                return this.Status == 1;
            }
        }

        public DateTime LastUpdated
        {
            get;
            set;
        }

        public string LastUpdateDateString
        {
            get
            {
                return LastUpdated.ToShortDateString();
            }
        }
    }
}
